home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / book / depthcue.c < prev    next >
C/C++ Source or Header  |  1998-12-15  |  4KB  |  103 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /*
  5.  * (c) Copyright 1993, Silicon Graphics, Inc.
  6.  * ALL RIGHTS RESERVED 
  7.  * Permission to use, copy, modify, and distribute this software for 
  8.  * any purpose and without fee is hereby granted, provided that the above
  9.  * copyright notice appear in all copies and that both the copyright notice
  10.  * and this permission notice appear in supporting documentation, and that 
  11.  * the name of Silicon Graphics, Inc. not be used in advertising
  12.  * or publicity pertaining to distribution of the software without specific,
  13.  * written prior permission. 
  14.  *
  15.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  16.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  17.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  18.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  19.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  20.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  21.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  22.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  23.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  24.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  25.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  26.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  * 
  28.  * US Government Users Restricted Rights 
  29.  * Use, duplication, or disclosure by the Government is subject to
  30.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  31.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  32.  * clause at DFARS 252.227-7013 and/or in similar or successor
  33.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  34.  * Unpublished-- rights reserved under the copyright laws of the
  35.  * United States.  Contractor/manufacturer is Silicon Graphics,
  36.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  37.  *
  38.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  39.  */
  40. /*
  41.  *  depthcue.c
  42.  *  This program draws a wireframe model, which uses 
  43.  *  intensity (brightness) to give clues to distance.
  44.  *  Fog is used to achieve this effect.
  45.  */
  46. #include <stdlib.h>
  47. #include <GL/glut.h>
  48.  
  49. /*  Initialize linear fog for depth cueing.
  50.  */
  51. void myinit(void)
  52. {
  53.     GLfloat fogColor[4] = {0.0, 0.0, 0.0, 1.0};
  54.  
  55.     glEnable(GL_FOG);
  56.     glFogi (GL_FOG_MODE, GL_LINEAR);
  57.     glHint (GL_FOG_HINT, GL_NICEST);  /*  per pixel   */
  58.     glFogf (GL_FOG_START, 3.0);
  59.     glFogf (GL_FOG_END, 5.0);
  60.     glFogfv (GL_FOG_COLOR, fogColor);
  61.     glClearColor(0.0, 0.0, 0.0, 1.0);
  62.  
  63.     glDepthFunc(GL_LESS);
  64.     glEnable(GL_DEPTH_TEST);
  65.     glShadeModel(GL_FLAT);
  66. }
  67.  
  68. /*  display() draws an icosahedron.
  69.  */
  70. void display(void)
  71. {
  72.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  73.     glColor3f (1.0, 1.0, 1.0);
  74.     glutWireIcosahedron();
  75.     glFlush();
  76. }
  77.  
  78. void myReshape(int w, int h)
  79. {
  80.     glViewport(0, 0, w, h);
  81.     glMatrixMode(GL_PROJECTION);
  82.     glLoadIdentity();
  83.     gluPerspective (45.0, (GLfloat) w/(GLfloat) h, 3.0, 5.0);
  84.     glMatrixMode(GL_MODELVIEW);
  85.     glLoadIdentity ();
  86.     glTranslatef (0.0, 0.0, -4.0);  /*  move object into view   */
  87. }
  88.  
  89. /*  Main Loop
  90.  */
  91. int main(int argc, char** argv)
  92. {
  93.     glutInit(&argc, argv);
  94.     glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  95.     glutCreateWindow(argv[0]);
  96.     myinit();
  97.     glutReshapeFunc(myReshape);
  98.     glutDisplayFunc(display);
  99.     glutMainLoop();
  100.     return 0;             /* ANSI C requires main to return int. */
  101. }
  102.  
  103.